import React from 'react';

class Timeloop extends React.Component{
  state = {
    time: '2020-11-04 15:17:22'
  }
  render(){
    return (
      <i>
        {this.state.time}
      </i>
    )
  }
  componentDidMount(){
    this.changtime()
  }
  changtime(){
    setInterval(()=>{
      let date = new Date()
      let str =  `
      ${date.getFullYear()}-${date.getMonth()<10 ? '0' + date.getMonth() : date.getMonth()}-${date.getDate()<10 ? '0' + date.getDate() : date.getDate()} 
      ${date.getHours()<10 ? '0' + date.getHours() : date.getHours()}:${date.getMinutes()<10 ? '0' + date.getMinutes() : date.getMinutes()}:${date.getSeconds()<10 ? '0' + date.getSeconds() : date.getSeconds()}
      `
      this.setState({
        time: str
      })
    },1000)
  }
}

export default Timeloop;